/*
 * Kelas lokasi pariwisata merupakan turunan dari kelas Kotak
 * Berisi setter, getter, dan method untuk membangun di lokasi pariwisata
 */

package model.board;
import helper.*;
import java.io.Serializable;
import model.players.*;

public class LokasiPariwisata extends Kotak implements Serializable
{
    //Attribute
    private String rekreasi;
    private int harga_rekreasi;
    private int increase_rekreasi;

    private String makanan;
    private int harga_makanan;
    private int increase_makanan;

    private int hargabeli_villa = 0;
    private int hargabeli_hotel = 0;
    private int hargasewa_villa = 0;
    private int hargasewa_hotel = 0;

    private int jum_villa = 0;
    private int jum_hotel = 0;

    public static LokasiPariwisata arrLP[] = new LokasiPariwisata[19];
    //getter
    
    public String getMakanan()
    {
        return makanan;
    }

    public int getHarga_makanan()
    {
        return harga_makanan;
    }

    public int getIncrease_makanan()
    {
        return increase_makanan;
    }

    public String getRekreasi()
    {
        return rekreasi;
    }
    
    public int getHarga_rekreasi()
    {
        return harga_rekreasi;
    }
    
    public int getIncrease_rekreasi()
    {
        return increase_rekreasi;
    }

    public int getHargabeli_villa ()
    {
        return hargabeli_villa;
    }

    public int getHargabeli_hotel ()
    {
        return hargabeli_hotel;
    }

    public int getHargajual_villa()
    {
        return hargabeli_villa/2;
    }

    public int getHargajual_hotel()
    {
        return hargabeli_hotel/2;
    }
    
    public int getHargajual_total()
    {
        return (getHargajual() + getHargajual_villa() + getHargajual_hotel());
    }

    public int getHargasewa_villa()
    {
        return hargasewa_villa;
    }

    public int getHargasewa_hotel()
    {
        return hargasewa_hotel;
    }

    @Override
    public int getHargasewa()
    {
        return (hargasewa + (jum_villa*hargasewa_villa) + (jum_hotel*hargasewa_hotel));
    }

    public int getJum_villa()
    {
        return jum_villa;
    }
    
    public int getJum_hotel()
    {
        return jum_hotel;
    }

    //setter
    
    public void setJumvilla (int _jumlah)
    {
        jum_villa = _jumlah;
    }

    public void setJumhotel (int _jumlah)
    {
        jum_hotel = _jumlah;
    }

    //constructor
    public LokasiPariwisata ()
    {
        super();
        
    }

    public LokasiPariwisata (int posisi)
    {
        super();
        nama = new String ((XMLReader.ArrLP[XMLReader.head]).getNama());
        kompleks = new String ((XMLReader.ArrLP[XMLReader.head]).getKompleks());


        rekreasi = new String ((XMLReader.ArrLP[XMLReader.head]).getRekreasi());
        harga_rekreasi = new Integer ( (XMLReader.ArrLP[XMLReader.head]).getHarga_rekreasi());
        increase_rekreasi = new Integer((XMLReader.ArrLP[XMLReader.head]).getIncrease_rekreasi());

        makanan = new String ( (XMLReader.ArrLP[XMLReader.head]).getMakanan());
        harga_makanan = new Integer ( (XMLReader.ArrLP[XMLReader.head]).getHarga_makanan());
        increase_makanan = new Integer ( (XMLReader.ArrLP[XMLReader.head]).getIncrease_makanan());

        hargabeli = new Integer ( (XMLReader.ArrLP[XMLReader.head]).getHargabeli());
        hargabeli_villa = new Integer ( (XMLReader.ArrLP[XMLReader.head]).hargabeli_villa);
        hargabeli_hotel = new Integer ( (XMLReader.ArrLP[XMLReader.head]).hargabeli_hotel);
        hargasewa = new Integer ( (XMLReader.ArrLP[XMLReader.head]).getHargasewa());
        hargasewa_villa = new Integer ( (XMLReader.ArrLP[XMLReader.head]).hargasewa_villa);
        hargasewa_hotel = new Integer ( (XMLReader.ArrLP[XMLReader.head]).hargasewa_hotel);


        XMLReader.NextHead(); //biar maju terus pantang mundur
        this.posisi = posisi;
        this.owner = null;
        this.jum_hotel = 0;
        this.jum_villa = 0;

    }

    public LokasiPariwisata
            (String _nama,
            String _kompleks,

            String _rekreasi,
            int _harga_rekreasi,
            int _increase_rekreasi,

            String _makanan,
            int _harga_makanan,
            int _increase_makanan,

            int _hargabeli_tanah,
            int _hargabeli_villa,
            int _hargabeli_hotel,

            int _hargasewa_tanah,
            int _hargasewa_villa,
            int _hargasewa_hotel)
    {
        nama = _nama;
        kompleks = _kompleks;

        rekreasi = _rekreasi;
        harga_rekreasi = _harga_rekreasi;
        increase_rekreasi = _increase_makanan;

        makanan = _makanan;
        harga_makanan = _harga_makanan;
        increase_makanan = _increase_makanan;

        hargabeli = _hargabeli_tanah;
        hargabeli_villa = _hargabeli_villa;
        hargabeli_hotel = _hargabeli_hotel;
        hargasewa = _hargasewa_tanah;
        hargasewa_villa = _hargasewa_villa;
        hargasewa_hotel = _hargasewa_hotel;

    }

    //method
    @Override
    public String PrintAttribute()
    {
        String retval = new String();
        retval = retval.concat("Name\t:"+this.nama);
        retval = retval.concat("\nComplex\t:"+this.kompleks);
        if (this.owner != null)
            retval = retval.concat("\n"+ ("Owner")+":"+this.owner.getNama());
        retval = retval.concat("\n\n"+ ("Recreation")+"\t:"+this.rekreasi);
        retval = retval.concat("\n"+ ("   Price")+"\t:"+this.harga_rekreasi);
        retval = retval.concat("\n"+ ("   Increase")+"\t:"+this.increase_rekreasi);

        retval = retval.concat("\n\n"+ ("Food")+"\t:"+this.makanan);
        retval = retval.concat("\n"+ ("   Price")+"\t:"+this.harga_makanan);
        retval = retval.concat("\n"+ ("   Increase")+"\t:"+this.increase_makanan);

        retval = retval.concat("\n\n"+ ("Buying Price ")+"\t:"+this.hargabeli);
        retval = retval.concat("\n"+ ("   Villa")+"\t:"+this.hargabeli_villa);
        retval = retval.concat("\n"+ ("   Hotel")+"\t:"+this.hargabeli_hotel);

        retval = retval.concat("\n\n"+ ("Renting Price")+"\t:"+this.hargasewa);
        retval = retval.concat("\n"+ ("   Villa")+"\t:"+this.hargasewa_villa);
        retval = retval.concat("\n"+ ("   Hotel")+"\t:"+this.hargasewa_hotel);

        retval = retval.concat("\n\n\n"+ ("Amount of Villa")+"\t:"+this.jum_villa);
        retval = retval.concat("\n"+ ("Amount of Hotel")+"\t:"+this.jum_hotel);
        return retval;

    }
//-----------------------------------METHOD---------------------------------
    
    //KONDISI UNTUK BELI VILLA
    public boolean BeliVilla (Player current_plyr)
    {
        boolean retval = false;
        //KONDISI : UANG CUKUP UNTUK BELI VILLA
        if (current_plyr.bayar(hargabeli_villa))
        {
            this.jum_villa +=1;
            retval = true;
        }
        //KONDISI : UANG TIDAK CUKUP UNTUK BELI VILLA
        else
            System.out.println("\tBuying process failed. Not sufficient fund.");

        return retval;
    }

    //KONDISI UNTUK BELI HOTEL
    public boolean BeliHotel (Player current_plyr)
    {
        boolean retval = false;
        //KONDISI : UANG CUKUP UNTUK BELI VILLA
        if (current_plyr.bayar(this.hargabeli_hotel))
        {
            this.jum_hotel += 1;
            this.jum_villa -= 4;
            retval = true;
        }
        //KONDISI : UANG TIDAK CUKUP UNTUK BELI VILLA
        else
            System.out.println("\tPembelian gagal. Not sufficient fund.");

        return retval;
    }

    public boolean Build (Player current_player)
    {
        boolean retval = false;
        if (jum_villa == 4)
        {
            retval = BeliHotel(current_player);
        }
        else
        {
            retval = BeliVilla(current_player);
        }
        return retval;
    }

    //KONDISI UNTUK JUAL TANAH
    public boolean bolehJual_Tanah (Kotak[] B, int lokasi, Player current_plyr)
    {
        boolean retval = false;

        for(int i = 1; i<= current_plyr.jum_aset+1;i++)
        {
            //KONDISI : BELUM PUNYA SATU KOMPLEKS, BOLEH LANGSUNG JUAL
            if(!SearchEngine.DoYouHaveThisComplex(B, posisi, current_plyr))
            {
                retval = true;
            }
            //KONDISI : SUDAH PUNYA SATU KOMPLEKS
            else
            {
                //KONDISI : TIDAK ADA VILLA ATAU HOTEL TERSISA DI KOMPLEKS
                if(SearchEngine.DoYouHaveZeroVillasOrHotelsRemainedInYourComplex( current_plyr, B,lokasi))
                {
                    retval = true;
                }
            }
        }
        return retval;
    }

        public static void puts (int S)
        {
            System.out.println(S);
        }

        public static void puts (String S)
        {
            System.out.println(S);
        }

        public static void main (String args[])
        {

            if (XMLReader.parseToArrLP("lokasi_pariwisata.xml", 18))
            {
                Kotak[] Board = new Kotak[33];
                for (int i = 1; i<=32; i++)
                {
                    Board[i] = new Kotak();
                    Board[i] = Board[i].newKotak(i);
                }

                LokasiPariwisata lok = (LokasiPariwisata)Board[2];
                Player P = new Player (1,"Anu","Ini",true);

                //TEST SETTER DAN GETTER
                puts("Nama: "+lok.getNama()+" Tipe: "+lok.getTipe()+" Kompleks: "+lok.getKompleks());
                puts("Harga beli: "+lok.getHargabeli()+" Harga jual: "+lok.getHargajual()+" Harga sewa: "+lok.getHargasewa());
                puts("Harga makanan: "+lok.getHarga_makanan()+" Increase: "+lok.getIncrease_makanan());
                puts("Harga rekreasi: "+lok.getHarga_rekreasi()+" Increase: "+lok.getIncrease_rekreasi());
                puts("Harga beli villa: "+lok.getHargabeli_villa()+" Harga jual villa: "+lok.getHargajual_villa()+" Harga sewa villa: "+lok.getHargasewa_villa());
                puts("Harga beli hotel: "+lok.getHargabeli_hotel()+" Harga jual hotel: "+lok.getHargajual_hotel()+" Harga sewa hotel: "+lok.getHargasewa_hotel());

                lok.BeliAset(P);
                lok.BeliVilla(P);
                lok.Build(P);
                
                puts("Jumlah hotel: "+lok.getJum_hotel()+" Jumlah villa: "+lok.getJum_villa());

                lok.setJumhotel(1);
                lok.setJumvilla(3);
                puts("Jumlah hotel: "+lok.getJum_hotel()+" Jumlah villa: "+lok.getJum_villa());

                if(lok.bolehJual_Tanah(Board, 2, P))
                    System.out.println("Boleh dijual");
                else
                    System.out.println("Tidak boleh dijual");

                puts(lok.PrintAttribute());

            }
        }
}
